package com.zmc.lostfound.post.controller;

import com.zmc.lostfound.common.utils.PageParams;
import com.zmc.lostfound.common.utils.PageResult;
import com.zmc.lostfound.common.utils.Result;
import com.zmc.lostfound.common.valid.AddGroup;
import com.zmc.lostfound.common.valid.UpdateGroup;
import com.zmc.lostfound.post.entity.PostImageEntity;
import com.zmc.lostfound.post.vo.PostImageSaveVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.zmc.lostfound.post.service.PostImageService;

import java.util.List;

/**
 * @author ZMC, GXC
 * @description 帖子图片信息管理控制层
 * @email 2869581855@qq.com
 * @date 2023-07-05 15:49:44
 */
@RestController
@RequestMapping("/postImage")
@Api(value = "帖子图片信息管理接口", tags = "帖子图片信息管理接口")
public class PostImageController {

    private final PostImageService postImageService;

    public PostImageController(PostImageService postImageService) {
        this.postImageService = postImageService;
    }

    @ApiOperation("分页查询帖子图片信息")
    @PostMapping("/query/page")
    public Result queryPage(@RequestBody @Validated PageParams pageParams) {
        PageResult pageResult = postImageService.queryPage(pageParams);
        return Result.ok("查询成功").put("pageResult", pageResult);
    }

    @ApiOperation("按帖子id查询全部图片信息")
    @GetMapping("/query/infoByPostId/{postId}")
    public Result queryInfoByPostId(@PathVariable("postId") Long postId) {
        List<PostImageEntity> postImageInfoList = postImageService.queryInfoByPostId(postId);
        return Result.ok("查询成功").put("postImageInfoList", postImageInfoList);
    }

    @ApiOperation("按主键id查询帖子图片信息")
    @GetMapping("/query/infoById/{id}")
    public Result queryInfoById(@PathVariable("id") Long id) {
        PostImageEntity postImageInfo = postImageService.queryInfoById(id);
        return Result.ok("查询成功").put("postImageInfo", postImageInfo);
    }

    @ApiOperation("新增帖子图片信息")
    @PostMapping("/insertPostImage")
    public Result insertPostImage(@RequestBody @Validated(value = {AddGroup.class}) PostImageSaveVO postImageSaveVO) {
        return postImageService.insertPostImage(postImageSaveVO);
    }

    @ApiOperation("修改帖子图片信息")
    @PutMapping("/updatePostImage")
    public Result updatePostImage(@RequestBody @Validated(value = {UpdateGroup.class}) PostImageSaveVO postImageSaveVO) {
        return postImageService.updatePostImage(postImageSaveVO);
    }

    @ApiOperation("批量删除帖子图片信息")
    @DeleteMapping("/deleteBatchByIds")
    public Result deleteBatchByIds(@RequestBody List<Long> ids) {
        return postImageService.deleteBatchByIds(ids);
    }

    @ApiOperation("按帖子id批量删除图片信息")
    @DeleteMapping("/deleteBatchByPostId/{postId}")
    public Result deleteBatchByPostId(@PathVariable("postId") Long postId) {
        return postImageService.deleteBatchByPostId(postId);
    }

}
